﻿#define _CRT_SECURE_NO_WARNINGS 1
#pragma once

//template <class Key, class T, class Compare = less<Key>, class Alloc = alloc>
//class map {
//public:
//    typedef Key key_type;
//    typedef pair<const Key, T> value_type;
//
//private:
//    typedef rb_tree<key_type, value_type,
//        select1st<value_type>, key_compare, Alloc> rep_type;
//    rep_type t;  // red-black tree representing map
//};
namespace bit
{
	template<class K,class V>
	class map
	{
		struct MapKeyOfT
		{
			const K& operator()(const pair<K, V>& kv)
			{
				return kv.first;
			}
		};
	public:
		typedef typename RBTree<K, pair<const K, V>, MapKeyOfT>::Iterator iterator;
		typedef typename RBTree<K, const K, MapKeyOfT>::ConstIterator const_iterator;

		
		const_iterator begin() const
		{
			return _t.Begin();
		}

		const_iterator end() const
		{
			return _t.End();
		}
		iterator begin()
		{
			return _t.Begin();
		}

		iterator end()
		{
			return _t.End();
		}
		iterator find(const K& key)
		{
			return _t.Find(key);
		}
		pair<iterator, bool>insert(const pair<K, V>& kv)
		{
			return _t.Insert(kv);
		}

		V& operator[](const K& key)
		{
			pair<iterator,bool>ret=_t.Insert(make_pair(key, V()));
			return ret.first->second;
		}


	private:
		RBTree< K, pair<const K, V>, MapKeyOfT> _t;

	};


	void test_map1()
	{
		map<string,int> m;
		m.insert({"苹果",1});
		m.insert({ "香蕉",1});
		m.insert({ "梨",1});
		m.insert({ "苹果",3 });

		map<string, int>::iterator it = m.begin();
		while (it != m.end())
		{
			//it->first += 'x';
			it->second += 1;
			//cout << it.operator->()->first << ":" << it->second << endl;
			cout << it->first << ":" << it->second << endl;
			++it;
		}
		cout << endl;
	}

	void test_map2()
	{
		string arr[] = { "ƻ", "", "ƻ", "", "ƻ", "ƻ", "",
"ƻ", "㽶", "ƻ", "㽶","ƻ","ݮ", "ƻ","ݮ" };
		map<string, int> countMap;
		for (auto& e : arr)
		{
			countMap[e]++;
		}

		for (auto& kv : countMap)
		{
			cout << kv.first << ":" << kv.second << endl;
		}
		cout << endl;
	}
}